﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetAllSubCategoryDataAction : BestLifeDataAction<List<Sub_Category>>
    {

        public BestLifeGetAllSubCategoryDataAction()
        {
            
        }

        public override List<Sub_Category> Body(SqlConnection PConn)
        {
            try
            {
                List<Sub_Category> LvList = new List<Sub_Category>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetAllSubCategory";

                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    Sub_Category LvSubCategory = new Sub_Category();
                    LvSubCategory.Subcat_ID = LvReader.GetValue(0).ToString();
                    LvSubCategory.Cat_ID = LvReader.GetValue(1).ToString();
                    LvSubCategory.Cat_Name = LvReader.GetValue(2).ToString();
                    LvSubCategory.Sub_Cat_Name = LvReader.GetValue(3).ToString();
                    LvSubCategory.Description = LvReader.GetValue(4).ToString();
                    LvSubCategory.Status = LvReader.GetValue(5).ToString();

                    LvList.Add(LvSubCategory);
                }
                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
